# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Chris Severance aur.severach AatT spamgourmet.com

_pyname=pcapy-ng
pkgname=python-pcapy
pkgver=1.0.5
pkgrel=2
pkgdesc='Extension module that interfaces with the libpcap packet capture library'
url='https://github.com/stamparm/pcapy-ng'
arch=('loong64' 'x86_64')
license=('Apache')
depends=('python' 'libpcap')
makedepends=('python' 'python-setuptools')
source=(https://github.com/stamparm/pcapy-ng/archive/${pkgver}/${_pyname}-${pkgver}.tar.gz python-3.11.patch)
sha256sums=('69b0294fdebbb2acd66f171e9b606db2fcd927d256674bb6681b9bdc2e0c5ca8'
            '530710ced8e3d580a76e0758c953b68ae3bd1222c857c5d5aa8cc4c47861dc37')
sha512sums=('aa41772541a769c4a4d8f76b46dac26079e5c66f915cfa57b9344186e5d823c928ea16bd327c35eecf8beaf0f74e881501d68d2583543142fecdb83ed7f9eafe'
            '30519deb17dc5c7230021c3452958b3a841695da480d2f8fc2e0ef4e704e1d6e98f858d51875ee3763ce8c949ca6df06e5d3234e947d0064403d777e70e3fb3e')

prepare() {
  cd ${_pyname}-${pkgver}
  sed -i '/self.assertEqual(refNone, sys.getrefcount(None))/d' tests/pcapytests.py

  # https://github.com/stamparm/pcapy-ng/issues/3#issuecomment-1082335450
  patch -Np1 -i ${srcdir}/python-3.11.patch
}

build() {
  cd ${_pyname}-${pkgver}
  python setup.py build
}

check() {
  cd ${_pyname}-${pkgver}/tests
  local PYTHONVERSION="$(python -c 'import sys; print("{}{}".format(sys.version_info.major, sys.version_info.minor))')"
  PYTHONPATH="../build/lib.linux-${CARCH}-cpython-${PYTHONVERSION}" \
    python pcapytests.py
}

package() {
  cd ${_pyname}-${pkgver}
  python setup.py install -O1 --root="${pkgdir}" --skip-build
  install -Dm 644 pcapy.html ChangeLog -t "${pkgdir}/usr/share/doc/${pkgname}"
  rm -r "${pkgdir}/usr/share/doc/${_pyname}"
}

# vim: ts=2 sw=2 et:
